home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 909 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.5 KB

  1. Path: chronicle.mti.sgi.com!austern
  2. From: davidb@datalytics.com (David Bradley)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Suggestion to the C++ standard
  5. Date: 29 Mar 1996 09:07:43 PST
  6. Organization: Datalytics Inc.
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <315c0f6e.956220382@news.datalytics.com>
  9. References: <4jatnm$s9b@post.tau.ac.il> <31599c95.4890732@nntp.ix.netcom.com>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: Fri, 29 Mar 1996 16:34:55 GMT
  12. X-Newsreader: Forte Agent .99d/32.182
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMVwY4Ey4NqrwXLNJAQGdJQIAtygERoHSMes/0QLdOJqEbi4YtF6sr+uy
  15.     04i9oWKkpHKTCDhSUEdVGdfRSSKbWhIa7dzlG5NxB//b0BJfmRqQ1w==
  16.     =zgef
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. jdmorris@ix.netcom.com (Jason D. Morris) wrote:
  20.  
  21. >#ifndef PROPERTY_H__
  22. >#define PROPERTY_H__
  23. >
  24. >// The property class controls access to a captive variable.
  25. >// It captures the get/set pattern.  This class first appeared
  26. >// in the November/December 1995 Vol. 7 / No. 9 Issue of C++ Report
  27. >// in the article Patterns in Practice: A property template for C++
  28. >// by Colin Hastie.
  29. >
  30. >template < class T >
  31. >class property
  32. >{
  33. >private:
  34. >    T content;  // captive variable
  35. >    
  36. >    // non-implemented non-accessible assignment operator
  37. >    void operator =( const property< T >& );
  38. >
  39. >public:
  40. >    // ctors
  41. >    property() {}
  42. >    property< T >( const T& t )
  43. >        : content( t )
  44. >    {}
  45. >
  46. >    // accessors
  47. >    T operator()() const   // get
  48. >    { return content; }
  49. >
  50. >    void operator()( const T& t )  // set
  51. >    { content = t; }
  52. >};
  53. >
  54. >#endif
  55. >
  56. >
  57. >To use this class you'd do something like this...
  58. >
  59. >class foo
  60. >{
  61. >public:
  62. >    property< int > foo_number;
  63. >};
  64.  
  65. On the surface this sounds good.  The obvious problem is the issue of
  66. access.  You may want the a private set and public get.
  67.  
  68. Another problem is you are unable to perform any validation within the
  69. set function.
  70.  
  71. Lastly the naming of the data member/accessors breaks most common
  72. styles.  Usually the member functions are distingiushed in some manner
  73. from the data members.
  74.  
  75. ===============================================
  76. DISCLAIMER: I may be a member of humanity,
  77. but I'm not a spokesman for humanity.
  78.     davidb@datalytics.com
  79. ---
  80. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  81.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  82.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  83.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  84.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  85. ]
  86.